<template>
    <div class="authority">
  
        <el-tabs
          type="border-card"
        >
          <el-tab-pane label="日报">
            <ShowByDate
              ref="showByDate"
              @changeRow="changeRow"
            />
          </el-tab-pane>
          <el-tab-pane label="月报">
            <ShowByMonth
              ref="showByMonth"
              @changeRow="changeRow"
            />
          </el-tab-pane>

        </el-tabs>
    </div>
  </template>
  
  <script setup>
  import {
    getAuthorityList,
    deleteAuthority,
    createAuthority,
    updateAuthority,
    copyAuthority
  } from '@/api/authority'
  
  import ShowByDate from '@/view/dataCenter/rechargeDataComponents/showByDate.vue'
  import ShowByMonth from '@/view/dataCenter/rechargeDataComponents/showByMonth.vue'
  
  import { ref } from 'vue'
  import { ElMessage, ElMessageBox } from 'element-plus'
  import { toDoc } from '@/utils/doc'
  import { VideoCameraFilled } from '@element-plus/icons-vue'
  
  defineOptions({
    name: 'Authority'
  })
  
  const mustUint = (rule, value, callback) => {
    if (!/^[0-9]*[1-9][0-9]*$/.test(value)) {
      return callback(new Error('请输入正整数'))
    }
    return callback()
  }
  
  const AuthorityOption = ref([
    {
      authorityId: 0,
      authorityName: '根角色'
    }
  ])
  const drawer = ref(false)
  const dialogType = ref('add')
  const activeRow = ref({})
  
  const dialogTitle = ref('新增角色')
  const dialogFormVisible = ref(false)
  const apiDialogFlag = ref(false)
  const copyForm = ref({})
  
  const form = ref({
    authorityId: 0,
    authorityName: '',
    parentId: 0
  })
  const rules = ref({
    authorityId: [
      { required: true, message: '请输入角色ID', trigger: 'blur' },
      { validator: mustUint, trigger: 'blur', message: '必须为正整数' }
    ],
    authorityName: [
      { required: true, message: '请输入角色名', trigger: 'blur' }
    ],
    parentId: [
      { required: true, message: '请选择父角色', trigger: 'blur' },
    ]
  })
  
  const page = ref(1)
  const total = ref(0)
  const pageSize = ref(999)
  const tableData = ref([])
  const searchInfo = ref({})
  
  // 查询
  const getTableData = async() => {
    const table = await getAuthorityList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
    if (table.code === 0) {
      tableData.value = table.data.list
      total.value = table.data.total
      page.value = table.data.page
      pageSize.value = table.data.pageSize
    }
  }
  
  getTableData()
  
  const changeRow = (key, value) => {
    activeRow.value[key] = value
  }
  const menus = ref(null)
  const apis = ref(null)
  const datas = ref(null)



  // 初始化表单
  const authorityForm = ref(null)
  const initForm = () => {
    if (authorityForm.value) {
      authorityForm.value.resetFields()
    }
    form.value = {
      authorityId: 0,
      authorityName: '',
      parentId: 0
    }
  }

  </script>
  
  <style lang="scss">
  .authority {
    .el-input-number {
      margin-left: 15px;
      span {
        display: none;
      }
    }
  }
  .tree-content{
    margin-top: 10px;
    height: calc(100vh - 158px);
    overflow: auto;
  }
  
  </style>
  